package com.woniuxy.lab.woniu_lab_boss.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.lab.woniu_lab_boss.common.Result;
import com.woniuxy.lab.woniu_lab_boss.exception.WebException;
import com.woniuxy.lab.woniu_lab_boss.exception.WebExceptionCode;
import com.woniuxy.lab.woniu_lab_boss.controller.form.ModifyRangeForm;
import com.woniuxy.lab.woniu_lab_boss.model.User;
import com.woniuxy.lab.woniu_lab_boss.service.UserService;
import com.woniuxy.lab.woniu_lab_boss.service.dto.RangeDto;
import com.woniuxy.lab.woniu_lab_boss.service.dto.UserDto;
import com.woniuxy.lab.woniu_lab_boss.util.EnumValue;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "[L]用户相关接口")
@Validated
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 修改用户账号状态，ENABLE->DISABLE   DISABLE->ENABLE
     * @param userId
     * @return
     */
    @ApiOperation("76 修改用户状态")
    @PutMapping("/modifyStatus")
    public Result modifyTeacherStatus(@ApiParam(value = "用户id") @RequestParam
                                          @NotNull(message = "用户ID不能为空")
                                          @Min(value = 1,message = "用户ID最小为1") Integer userId) {
        log.info("修改用户{}的状态", userId);
        userService.modifyStatus(userId);
        return Result.success(200, "修改用户状态成功", null);
    }

    /**
     * 根据keyword查询用户
     * @param condition
     * @param page
     * @param size
     * @return
     */
    @ApiOperation("78 关键词搜索用户")
    @GetMapping("/query")
    public Result<IPage<UserDto>> queryUser(
            @ApiParam(value = "关键词")String condition,
            @ApiParam(value = "第几页") @Min(value = 1,message="页码必须大于1") Integer page,
            @ApiParam(value = "每页条数") @Min(value = 1,message="每页展示数必须大于1") @Max(value = 10,message = "每页展示数不能大于10") Integer size
    ) {
        log.info("查询用户{}{}{}", condition, page, size);
        IPage<UserDto> page1 = userService.search(condition, page, size);
        return Result.success(200, "关键词查询用户成功", page1);
    }

    /**
     * 查询所有用户
     * @param page
     * @param size
     * @return
     */
    @ApiOperation("77 查询所有用户")
    @GetMapping("/queryAll")
    public Result<IPage<UserDto>> queryAllUser(@ApiParam(value = "第几页") @Min(value = 1,message="页码必须大于1") Integer page, @ApiParam(value = "每页条数") @Min(value = 1,message="每页展示数必须大于1") @Max(value = 10,message = "每页展示数不能大于10") Integer size) {
        log.info("查询用户{}{}", page, size);
        IPage<UserDto> page1 = userService.findAll(page, size);
        return Result.success(200, "查询成功", page1);
    }

    /**
     * 查询VIP用户
     * @param page
     * @param size
     * @return
     */
    @ApiOperation("79 按会员类别查询用户")
    @GetMapping("/queryVIP")
    public Result<IPage<UserDto>> findVIP(
            @ApiParam(value = "第几页") @Min(value = 1,message="页码必须大于1") Integer page,
            @ApiParam(value = "每页条数") @Min(value = 1,message="每页展示数必须大于1") @Max(value = 10,message = "每页展示数不能大于10") Integer size,
            @ApiParam(value = "会员类别") @EnumValue(strValues = {"VIP","SVIP","NORMAL"},message = "类别只能是VIP|SVIP|NORMAL") String vip
    ) {
        log.info("查询{}用户{}{}", vip,page, size);
        IPage<UserDto> page1 = userService.findVIP(vip,page, size);
        return Result.success(200, "根据VIP情况查询用户成功", page1);
    }
}

